package com.newland.starpos.partner.utils;

import java.util.Random;

/**
 * Created by liuNW on 2018/9/28.
 */
public class GenerateUtils {

    private static final Random random = new Random();

    public static String getRequestId() {
        return String.valueOf(System.currentTimeMillis()) + random.nextInt(1000);
    }

    public static String getAuthCode() {
        String code  = String.valueOf(random.nextInt(1000000));
        if(code.length() != 6){
            return getAuthCode();
        }
        return code;
    }

    public static String randomNumOrChar(Integer length, Boolean upperCase) {
        int count = 0;
        if (length != null) {
            count = length.intValue();
        }
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < count; i++) {
            double d = (random.nextInt(2) % 2 == 0) ? (Math.random() * 9 + 49) : (Math.random() * 26 + 97);
            char c = (char) (int) (d);
            sb.append(c);
        }
        return (upperCase != null && upperCase) ? sb.toString().toUpperCase() : sb.toString();
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++){
            System.out.println(GenerateUtils.getAuthCode());
        }
    }
}
